<%@ page pageEncoding="UTF-8"%>
<%@ include file="../commons/head.jsp"%>
<title>用户新增</title>
<head>
<script type="text/javascript">
</script>
</head>
<body>
<div class="jianju" style="height: 1000px;">
<h3>合同高级查询</h3>

<div id="tb" style="padding:5px;height:auto">
<hr/>
	<div>
	  <label style="margin-left:18px"><span style="color:red;">*</span>登陆代码：</label><input class="easyui-textbox" data-options="validType:'length[0,20]'" id="userId" type="number" style="width:120px">
	  <label style="margin-left:18px"><span style="color:red;">*</span>用户姓名：</label><input class="easyui-textbox" data-options="validType:'length[0,50]'" id="userName" style="width:110px"><br />
	  <label style="margin-left:18px"><span style="color:red;">*</span>所属公司：</label>
	     <select id="ssgs" class="easyui-combobox" style="width: 100px" 
			mode="remote" url="${ctx}/contractadvancedquery/findUnderCompany" valueField="id"
			textField="orgName" method="get" editable="false" panelHeight="auto">
		 </select><br />
	  <label style="margin-left:18px"><span style="color:red;">*</span>用户角色：</label>
	     <select id="yhjs" class="easyui-combobox" style="width: 100px" 
			mode="remote" url="${ctx}/Boxuser/userfindName" valueField="roleId"
			textField="roleName" method="get" editable="false" panelHeight="auto">
		 </select>
	  <label style="margin-left:18px">联系电话：</label><input type="number" class="easyui-textbox" data-options="validType:'length[0,20]'" id="phone" style="width:110px"><br />
	  <label style="margin-left:18px">备用手机号码：</label><input type="number" class="easyui-textbox" data-options="validType:'length[0,20]'" id="mobile" type="number" style="width:120px">
	  <label style="margin-left:18px">电子邮件：</label><input class="easyui-textbox" data-options="validType:'length[0,100]'" id="email" style="width:110px"><br />
	  <label style="margin-left:18px">用户备注：</label><textarea class="easyui-textbox" data-options="validType:'length[0,1000]'" id="memo" style="width:220px;height: 50px;"></textarea><br />
		 <br />
	<div id="dlg-buttons">
		<a href="#" class="easyui-linkbutton" iconCls="icon-ok" onclick="saved();">保存</a>
		<a href="#" class="easyui-linkbutton" iconCls="icon-cancel" onclick="javascript:reload();">返回</a>
	</div>
	</div> 
</div> 
<script type="text/javascript">
function reload(closeFlag){
	window.history.go(-1);
} 
$(function(){
	$('#ssgs').combobox({
		onLoadSuccess : function() {
			var data = $('#ssgs').combobox('getData');
			if (data) {
				$("#ssgs").combobox('select', data[0].id);
			}
		}
	}); 
	$('#yhjs').combobox({
		onLoadSuccess : function() {
			var data = $('#yhjs').combobox('getData');
			if (data) {
				$("#yhjs").combobox('select', data[5].roleId);
			}
		}
	}); 
});

function saved(){debugger
	var userId = $("#userId").val();
	var userName = $("#userName").val();
	var underCompany = $("#ssgs").combobox("getValue");
	var roleId = $("#yhjs").combobox("getValue");
	var phone = $("#phone").val();
	var mobile = $("#mobile").val();
	var email = $("#email").val();
	var memo = $("#memo").val();
	if(userId == "" || userName == "" || underCompany == "" || roleId ==""){
		alert(" * 为必填项");
	}else{
		if(userId.length > 11 || userName.length > 50 || phone.length > 20 || mobile.length > 20 || email.length > 100 || memo.length > 1000){
			alert("超过字数限制请修改！");
		}else{
			$.ajax({
				url:"${ctx}/Boxuser/findUserByUserId",
				data:{"userId":userId},
				success:function(data){debugger
					if(data != "" && data != null){
						//$("#userId").val("");
						alert("登陆代码已存在！");
					}else{
						$.ajax({
							url:"${ctx}/Boxuser/savetoUser",
							data:{"userId":userId,"userName":userName,"underCompany":underCompany,"phone":phone,"mobile":mobile,"email":email,"memo":memo},
							success:function(data){debugger
								if(data.result == 1){
									alert("保存到用户表成功！初始密码为12345678");
									$.ajax({
										url:"${ctx}/Boxuser/savetoUserRole",
										data:{"userId":userId,"roleId":roleId},
										success:function(data){debugger
											if(data.result == 1){
												alert("保存到用户角色表成功！");
											}else{
												alert("保存到用户角色表失败！");
											}
										}
									});
								}else{
									alert("保存到用户表失败！");
								}
							} 
						});
					}
				}
			});
		}
	}
}
</script>


</div> 
</body>
</html>